package com.example.csetpp.utils;

import java.util.regex.Pattern;

/**
 * 邮箱验证工具类
 */
public class EmailValidator {
    
    /**
     * 邮箱格式正则表达式
     */
    private static final String EMAIL_REGEX = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
    
    private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX);
    
    /**
     * 验证邮箱格式是否正确
     * @param email 待验证的邮箱
     * @return 如果邮箱格式正确返回true，否则返回false
     */
    public static boolean isValidEmail(String email) {
        if (email == null) {
            return false;
        }
        return EMAIL_PATTERN.matcher(email).matches();
    }
}